package com.ganeshkrishnan.globald.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.ganeshkrishnan.globald.abstracts.GenericDaoHibernate;
import com.ganeshkrishnan.globald.dao.MilResourceDao;
import com.ganeshkrishnan.globald.model.MilResource;

@Repository
@Transactional
public class MilResourceDaoHibernate extends GenericDaoHibernate<MilResource, Long> implements MilResourceDao {
	public MilResourceDaoHibernate() {
		super(MilResource.class);
	}

	@SuppressWarnings("unchecked")
	public List<MilResource> findAllResourcesByPersonID(Long PersonID) {
		return getHibernateTemplate().find("from MilResource where PersonID=?", PersonID);
	}

	@SuppressWarnings("unchecked")
	public MilResource findResourceByPerson(Long PersonID, int resType)
	{
		List<MilResource> list = getHibernateTemplate().find("from MilResource where PersonID=? and unitType=?", PersonID, resType);
		
		if(null==list) return null;
		else return list.get(0);
	}
	
	
	//Use the parent save method which uses "merge"
	@Deprecated
	public MilResource UpdateResource(MilResource resource) {
		getHibernateTemplate().saveOrUpdate(resource);
		getHibernateTemplate().flush();
		return resource;
	}
}
